package ListNodePractice;

public class OddEvenList {
    public static ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return null;
        }
        //定义奇数和偶数的链表
        ListNode oddList = head;
        ListNode evenList = head.next;
        //定义偶链表的头结点
        ListNode evenHead = evenList;
        while (evenList != null && evenList.next != null) {
            oddList.next = evenList.next;
            oddList = oddList.next;
            evenList.next=oddList.next;
            evenList=evenList.next;
        }
        oddList.next = evenHead;
        return head;
    }

    public static void main(String[] args) {
        ListNode listNode0 = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);
        ListNode listNode3 = new ListNode(4);
        listNode0.next = listNode1;
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        System.out.println(oddEvenList(listNode0));
    }
}
